// pages/regimental/regimental.js
import baseuser from '~/utils/users.js'
import baseteam from '~/utils/teamleader.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    settop: 0,
    show: false,
    kefucode:'',


    checked1: true,
    checked2: false,

    pages: 1,
    regilist: [],

    value:"",
    newdatas:[]
  },
  navehomepage(items) {
    wx.navigateTo({
      url: `/my/myhomepages/myhomepages?id=${items.currentTarget.dataset.select}`,

    })
  },
  goRegimentalSearch(){
wx.navigateTo({
  url: '/search/regimentalSearch/regimentalSearch',
})
  },
  async getregimdata() {
    let setdata = {
      "page": this.data.pages,
      "pageSize": "10",
      "storeName": "",
      "categoryName": "",
      "synthesis": "",
      "area": "",
    }
    let reqdata = await baseuser.teamleader(setdata)
    console.log(reqdata)
    this.setData({
      regilist: reqdata.data.data.items.records
    })
   
  },
async bannar(){
  let setData={
    query:'团长榜Banner'
  }
let readata= await baseteam.banner(setData)
console.log('readata1111111111',readata);
this.setData({
 newdatas:readata.data.item
})
},
async getcode() {
  let resdata = await baseuser.getcde()
  console.log('resdata.data.item.code',resdata.data.item.code)
  this.setData({
      kefucode: resdata.data.item.code
  })
},
lianxikefu() {
console.log('000');
  this.setData({
      show: true
  })
},
onClose() {
  this.setData({
      show: false
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.bannar()
 
    this.getcode()
    let Bartop = (0, wx.getMenuButtonBoundingClientRect)().top;
    let BarHeight = (0, wx.getMenuButtonBoundingClientRect)().height;

    console.log(wx.getMenuButtonBoundingClientRect())
    this.setData({
      settop: Bartop + BarHeight * 1.5
    })
    this.getregimdata()
  },
  async chengeflow(items) {
    console.log(items)
    let setdata = {
      "beUserId": this.data.regilist[items.currentTarget.dataset.select].userId,
    }
    let setnewdat = `regilist[${items.currentTarget.dataset.select}]`
    let newdatas = this.data.regilist[items.currentTarget.dataset.select]
    let reqdata = await baseteam.addfollow(setdata)
    newdatas.isFollow = reqdata.data.data.state
    if (reqdata.code == 200) {
      wx.showToast({
        title: reqdata.data.data.message,
        icon: 'success',
        duration: 2000
      })
      this.setData({
        [setnewdat]: newdatas
      })
    } else {
      wx.showToast({
        title: '操作失败',
        icon: 'error',
        duration: 2000
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})